package com.example.widgetcase.slice;

import com.example.widget_lib.widget.progress.horbar.HorProBar;
import com.example.widgetcase.ResourceTable;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;

import java.security.SecureRandom;
import java.util.Random;

public class HorProBarAbility extends BaseSlice {

    private SecureRandom mRandom = new SecureRandom();
    private HorProBar hbBar1;
    private HorProBar hbBar2;
    private HorProBar hbBar3;

    @Override
    public int getChildUIContent() {
        return ResourceTable.Layout_horprobar;
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        hbBar1 = (HorProBar) findComponentById(ResourceTable.Id_horprobar1);
        hbBar2 = (HorProBar) findComponentById(ResourceTable.Id_horprobar2);
        hbBar3 = (HorProBar) findComponentById(ResourceTable.Id_horprobar3);
        Button button = (Button) findComponentById(ResourceTable.Id_button);

        hbBar1.setCurrentProgress(0f);
        hbBar2.setCurrentProgress(52.3f);
        hbBar3.setCurrentProgress(122.5f);

        button.setClickedListener(component -> {
            hbBar1.setCurrentProgress(mRandom.nextFloat() * 100);
            hbBar2.setCurrentProgress(mRandom.nextFloat() * 100);
            hbBar3.setCurrentProgress(mRandom.nextFloat() * 200);
        });
    }
}
